#ifndef __ILIB_CORE_MSG_H_20120131__
#define __ILIB_CORE_MSG_H_20120131__

#include "iTimer.h"

typedef unsigned int iMsgID;
#define MSG_TIMER		0

class iMsg 
{
public:
	class iSink
	{
	public:
		virtual int on_message(iMsgID msg, void* param) = 0;
	};

	static iMsg* new_instance(iMsgID id, void* param, iSink* handler);

protected:
	iMsg(iMsgID id, void* param, iSink* handler) : m_id(id), m_param(param), m_handler(handler){}

public:
	inline void process() 
	{ 
		switch(m_id)
		{
		case MSG_TIMER:
			{
				if(((iTimer*)m_param)->is_release() == false)
					((iTimer*)m_param)->get_sink()->on_timer((iTimer*)m_param);
				else if(((iTimer*)m_param)->is_stopped())
					((iTimer*)m_param)->release();
			}
			break;
		default:
			m_handler->on_message(m_id, m_param);
			break;
		}
	}

protected:
	iMsgID	m_id;
	void*	m_param;
	iSink*	m_handler;
};




#endif  //__ILIB_CORE_MSG_H_20120131__
